<?php

use App\Http\Controllers\admin\CompanyController;
use App\Http\Controllers\admin\DisclosureController;
use App\Http\Controllers\admin\DisclosureTypeController;
use App\Http\Controllers\admin\NotifyController;
use App\Http\Controllers\admin\RoleController;
use App\Http\Controllers\admin\ProjectController;
use App\Http\Controllers\admin\QualityController;
use App\Http\Controllers\admin\QualityTypeController;
use App\Http\Controllers\admin\ResourceController;
use App\Http\Controllers\admin\SafeController;
use App\Http\Controllers\admin\SafeTypeController;
use App\Http\Controllers\admin\ScheduleController;
use App\Http\Controllers\admin\ScheduleRecordController;
use App\Http\Controllers\admin\ScheduleTypeController;
use App\Http\Controllers\admin\UserController;
use App\Http\Controllers\UploadController;
use App\Http\Controllers\UserController as AppUserController;
use App\Http\Controllers\ScheduleController as AppScheduleController;
use App\Http\Controllers\ScheduleRecordController as AppScheduleRecordController;
use App\Http\Controllers\DisclosureController as AppDisclosureController;
use App\Http\Controllers\SafeController as AppSafeController;
use App\Http\Controllers\QualityController as AppQualityController;
use App\Http\Controllers\ProjectController as AppProjectController;
use App\Http\Controllers\StatisticsController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
    return $request->user();
});

Route::post('/login', [AppUserController::class, 'login']);
Route::group(['middleware' => ['auth:api']], function () {
    
    Route::post('/upLoadFIle', [UploadController::class, 'upLoadFIle']);
    Route::post('/statistics', [StatisticsController::class, 'index'])->middleware('CheckProject');
    Route::post('/temp/complete', [StatisticsController::class, 'tempComplete'])->middleware('CheckProject');
    Route::post('/temp', [StatisticsController::class, 'temp'])->middleware('CheckProject');

    Route::post('/user', [AppUserController::class, 'index']);
    Route::post('/user/statistics', [AppUserController::class, 'statistics']);
    Route::post('/user/statisticsList', [AppUserController::class, 'statisticsList']);
    Route::patch('/user', [AppUserController::class, 'update']);
    Route::post('/user/projects', [AppUserController::class, 'projects']);
    Route::post('/project/user', [AppProjectController::class, 'user']);
    

    Route::post('/schedule', [AppScheduleController::class, 'index']);
    Route::post('/schedule/statistics', [AppScheduleController::class, 'statistics']);
    Route::post('/schedule/complete', [AppScheduleController::class, 'complete'])->middleware('CheckProject');
    Route::get('/schedule/{id}', [AppScheduleController::class, 'show']);
    Route::put('/schedule/record', [AppScheduleRecordController::class, 'store'])->middleware('CheckProject');
    Route::patch('/schedule/record', [AppScheduleRecordController::class, 'update'])->middleware('CheckProject');

    Route::get('/disclosure/{id}', [AppDisclosureController::class, 'show']);
    Route::post('/disclosure', [AppDisclosureController::class, 'index']);

    Route::get('/safe/{id}', [AppSafeController::class, 'show']);
    Route::get('/safeTemp/{id}', [AppSafeController::class, 'tempShow']);
    Route::post('/safe', [AppSafeController::class, 'index'])->middleware('CheckProject');
    Route::post('/safe/statistics', [AppSafeController::class, 'statistics'])->middleware('CheckProject');
    Route::post('/safe/complete', [AppSafeController::class, 'complete'])->middleware('CheckProject');
    Route::put('/safe/inspect', [AppSafeController::class, 'store'])->middleware('CheckProject');
    Route::post('/safe/temp', [AppSafeController::class, 'temps'])->middleware('CheckProject');
    Route::put('/safe/temp', [AppSafeController::class, 'insertTemp'])->middleware('CheckProject');

    Route::get('/quality/{id}', [AppQualityController::class, 'show']);
    Route::get('/qualityTemp/{id}', [AppQualityController::class, 'tempShow']);
    Route::post('/quality', [AppQualityController::class, 'index'])->middleware('CheckProject');
    Route::post('/quality/statistics', [AppQualityController::class, 'statistics'])->middleware('CheckProject');
    Route::post('/quality/complete', [AppQualityController::class, 'complete'])->middleware('CheckProject');
    Route::put('/quality/inspect', [AppQualityController::class, 'store'])->middleware('CheckProject');
    Route::post('/quality/temp', [AppQualityController::class, 'temps'])->middleware('CheckProject');
    Route::put('/quality/temp', [AppQualityController::class, 'insertTemp'])->middleware('CheckProject');
});

Route::group(['prefix' => 'admin'], function () {
    Route::post('/login', [UserController::class, 'login']);

    Route::group(['middleware' => ['auth:api']], function () {
        Route::get('/uploadToken', [UploadController::class, 'getToken']);
        Route::post('/statistics', [StatisticsController::class, 'index'])->middleware('CheckProject');
        
        Route::get('/user/{id}', [UserController::class, 'show']);
        Route::post('/user', [UserController::class, 'index']);
        Route::post('user/statistics', [UserController::class, 'statistics']);
        Route::post('/user/userStatisticsList', [UserController::class, 'userStatisticsList']);
        Route::put('/user', [UserController::class, 'store']);
        Route::patch('/user', [UserController::class, 'update']);
        Route::patch('/user/status', [UserController::class, 'status']);
        Route::delete('/user/{id}', [UserController::class, 'delete']);
    
        Route::get('/role/{id}', [RoleController::class, 'show']);
        Route::post('/role', [RoleController::class, 'index']);
        Route::put('/role', [RoleController::class, 'store']);
        Route::patch('/role', [RoleController::class, 'update']);
        Route::patch('/role/status', [RoleController::class, 'status']);
        Route::delete('/role/{id}', [RoleController::class, 'delete']);
    
        Route::get('/company/{id}', [CompanyController::class, 'show']);
        Route::post('/company', [CompanyController::class, 'index']);
        Route::put('/company', [CompanyController::class, 'store']);
        Route::patch('/company', [CompanyController::class, 'update']);
        Route::patch('/company/status', [CompanyController::class, 'status']);
        Route::delete('/company/{id}', [CompanyController::class, 'delete']);
    
        Route::get('/project/{id}', [ProjectController::class, 'show']);
        Route::post('/project', [ProjectController::class, 'index']);
        Route::post('/project/selectList', [ProjectController::class, 'selectList']);
        Route::put('/project', [ProjectController::class, 'store']);
        Route::patch('/project', [ProjectController::class, 'update']);
        Route::patch('/project/status', [ProjectController::class, 'status']);
        Route::delete('/project/{id}', [ProjectController::class, 'delete']);

        Route::post('/userBindProject', [UserController::class, 'userBindProject']);
        Route::post('/projectBindUser', [ProjectController::class, 'projectBindUser']);

        Route::get('/resource/{id}', [ResourceController::class, 'show']);
        Route::post('/resource', [ResourceController::class, 'index'])->middleware('CheckProject');
        Route::put('/resource', [ResourceController::class, 'store'])->middleware('CheckProject');
        Route::patch('/resource', [ResourceController::class, 'update'])->middleware('CheckProject');
        Route::delete('/resource/{id}', [ResourceController::class, 'delete']);


        Route::get('/schedule/{id}', [ScheduleController::class, 'show']);
        Route::post('/schedule', [ScheduleController::class, 'index'])->middleware('CheckProject');
        Route::post('/schedule/import', [ScheduleController::class, 'import'])->middleware('CheckProject');
        Route::post('/schedule/statistics', [ScheduleController::class, 'statistics'])->middleware('CheckProject');
        Route::put('/schedule', [ScheduleController::class, 'store'])->middleware('CheckProject');
        Route::patch('/schedule', [ScheduleController::class, 'update'])->middleware('CheckProject');
        Route::delete('/schedule/{id}', [ScheduleController::class, 'delete']);

        Route::post('/schedule/type', [ScheduleTypeController::class, 'index'])->middleware('CheckProject');
        Route::put('/schedule/type', [ScheduleTypeController::class, 'store'])->middleware('CheckProject');
        Route::patch('/schedule/type', [ScheduleTypeController::class, 'update'])->middleware('CheckProject');
        Route::delete('/schedule/type/{id}', [ScheduleTypeController::class, 'delete']);

        Route::get('/scheduleRecord/{id}/{type}', [ScheduleRecordController::class, 'show']);
        Route::post('/schedule/record', [ScheduleRecordController::class, 'index'])->middleware('CheckProject');
        Route::put('/schedule/record', [ScheduleRecordController::class, 'store'])->middleware('CheckProject');
        Route::patch('/schedule/record', [ScheduleRecordController::class, 'update'])->middleware('CheckProject');
        Route::delete('/schedule/type/{id}', [ScheduleRecordController::class, 'delete']);


        Route::get('/disclosure/{id}', [DisclosureController::class, 'show']);
        Route::post('/disclosure', [DisclosureController::class, 'index'])->middleware('CheckProject');
        Route::put('/disclosure', [DisclosureController::class, 'store'])->middleware('CheckProject');
        Route::patch('/disclosure', [DisclosureController::class, 'update'])->middleware('CheckProject');
        Route::delete('/disclosure/{id}', [DisclosureController::class, 'delete']);

        Route::post('/userBindDisclosure', [UserController::class, 'userBindDisclosure']);
        Route::post('/disclosureBindUser', [DisclosureController::class, 'disclosureBindUser']);

        Route::post('/disclosure/type', [DisclosureTypeController::class, 'index'])->middleware('CheckProject');
        Route::put('/disclosure/type', [DisclosureTypeController::class, 'store'])->middleware('CheckProject');
        Route::patch('/disclosure/type', [DisclosureTypeController::class, 'update'])->middleware('CheckProject');
        Route::delete('/disclosure/type/{id}', [DisclosureTypeController::class, 'delete']);


        Route::post('/safe/type', [SafeTypeController::class, 'index'])->middleware('CheckProject');
        Route::get('/safe/type/{id}', [SafeTypeController::class, 'show']);
        Route::put('/safe/type', [SafeTypeController::class, 'store'])->middleware('CheckProject');
        Route::patch('/safe/type', [SafeTypeController::class, 'update'])->middleware('CheckProject');
        Route::delete('/safe/type/{id}', [SafeTypeController::class, 'delete']);

        Route::get('/safe/{id}', [SafeController::class, 'show']);
        Route::post('/safe', [SafeController::class, 'index'])->middleware('CheckProject');
        Route::post('/safe/statistics', [SafeController::class, 'statistics'])->middleware('CheckProject');
        Route::put('/safe', [SafeController::class, 'store'])->middleware('CheckProject');
        Route::patch('/safe', [SafeController::class, 'update'])->middleware('CheckProject');
        Route::delete('/safe/{id}', [SafeController::class, 'delete']);

        Route::post('/quality/type', [QualityTypeController::class, 'index'])->middleware('CheckProject');
        Route::get('/quality/type/{id}', [QualityTypeController::class, 'show']);
        Route::put('/quality/type', [QualityTypeController::class, 'store'])->middleware('CheckProject');
        Route::patch('/quality/type', [QualityTypeController::class, 'update'])->middleware('CheckProject');
        Route::delete('/quality/type/{id}', [QualityTypeController::class, 'delete']);

        Route::get('/quality/{id}', [QualityController::class, 'show']);
        Route::post('/quality', [QualityController::class, 'index'])->middleware('CheckProject');
        Route::post('/quality/statistics', [QualityController::class, 'statistics'])->middleware('CheckProject');
        Route::put('/quality', [QualityController::class, 'store'])->middleware('CheckProject');
        Route::patch('/quality', [QualityController::class, 'update'])->middleware('CheckProject');
        Route::delete('/quality/{id}', [QualityController::class, 'delete']);

        Route::get('/notify/{id}', [NotifyController::class, 'show']);
        Route::post('/notify', [NotifyController::class, 'index'])->middleware('CheckProject');
        Route::put('/notify', [NotifyController::class, 'store'])->middleware('CheckProject');
        Route::patch('/notify', [NotifyController::class, 'update'])->middleware('CheckProject');
        Route::delete('/notify/{id}', [NotifyController::class, 'delete']);

    });
});